class Vendor < ActiveRecord::Base
  has_many :products
  has_many :purchase_order
  belongs_to :company
  belongs_to :adder, :class_name => 'Employee', :foreign_key => 'add_id'
  belongs_to :editor, :class_name => 'Employee', :foreign_key => 'edit_id'

  scope :name_like, lambda {  |name,for_cbb|
    if for_cbb == 'false'
      where('name like ?', '%'+name+'%')
    else
      where('name like ? AND is_locked = 0', '%'+name+'%').select([:id,:name,:number,:phone,:linkman])
    end
  }
end
